package com.site.model.backend.system;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.site.util.base.po.BaseApplicationInfo;


/**
 * 角色
 * @author lee 2012-10-12
 *
 */
@Entity
@Table(name="m_system_role")
public class RoleInfo extends BaseApplicationInfo{
	private static final long serialVersionUID = 1L;
	/*
	 * 角色id
	 */
	private Long id;
	/*
	 * 角色名称
	 */
	private String roleName;
	/*
	 * 备注
	 */
	private String description;
	
	/*
	 * 用户
	 */
	private Set<UsersInfo> userSet; 
	/*
	 * 资源
	 */
	private Set<ResourseInfo> resourseSet;
	
	/*
	 * 权限
	 */
	private Set<AuthorityInfo> authoritySet;
	
	@Id
	@Column(name = "Id")
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "increment")
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	@Column(name = "role_Name")
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@ManyToMany(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)
	@JoinTable(name = " m_system_role_user", joinColumns = @JoinColumn(name="role_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
	public Set<UsersInfo> getUserSet() {
		return userSet;
	}
	public void setUserSet(Set<UsersInfo> userSet) {
		this.userSet = userSet;
	}
	
	@OneToMany(fetch = FetchType.LAZY)
	@JoinTable(name="m_system_role_resource", joinColumns = @JoinColumn(name="role_id"), inverseJoinColumns = @JoinColumn(name = "resource_id"))
	public Set<ResourseInfo> getResourseSet() {
		return resourseSet;
	}

	public void setResourseSet(Set<ResourseInfo> resourseSet) {
		this.resourseSet = resourseSet;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name="m_system_role_authority", joinColumns = @JoinColumn(name="role_id"), inverseJoinColumns = @JoinColumn(name="AUTHORITY_ID"))
	public Set<AuthorityInfo> getAuthoritySet() {
		return authoritySet;
	}

	public void setAuthoritySet(Set<AuthorityInfo> authoritySet) {
		this.authoritySet = authoritySet;
	}
}
